package Euler46;

import java.util.*;
import ReusableCode.PrimeFunctions;

public class Goldbach {
	public static void main(String[] args) {
		int max = 1000000;
		HashSet<Integer> primesHash = PrimeFunctions.GetPrimesHash(max);
		List<Integer> primes = PrimeFunctions.GetPrimes(max);
		List<Integer> squares = new ArrayList<Integer>();
		
		//Generate all double squares.
		int temp = 0;
		int count = 1;
		while(temp<max)
		{
			temp = 2 * (count * count);
			squares.add(temp);
			count++;
		}
		
		for(int i = 9; i < max; i+=2)
		{
			if(!primesHash.contains(i))
			{
				boolean exists = false;
				for(int j = 0; j < primes.size(); j++)
				{
					int prime = primes.get(j);
					boolean brk = false;
					long val = 0;
					count = 0;
					while((val < i) && (count < squares.size()))
					{
						val = prime + squares.get(count);
						if(val==i)
						{
							brk=true;
							exists=true;
							break;
						}
						count++;
					}
					
					if(brk)
					{
						break;
					}
				}
				
				if(!exists)
				{
					System.out.println("The number is: " + i);
					break;
				}
			}
		}
	}
}
